<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%@ include file="/commons/global.jsp" %>
<script type="text/javascript">
    var wechatServiceDataGrid;
    $(function() {
        wechatServiceDataGrid = $('#wechatServiceDataGrid').datagrid({
            url : '${path }/wechatService/dataGrid',
            striped : true,
            rownumbers : true,
            pagination : true,
            singleSelect : true,
            idField : 'id',
            sortName : 'id',
            sortOrder : 'asc',
            pageSize : 20,
            pageList : [ 10, 20, 30, 40, 50, 100, 200, 300, 400, 500 ],
            frozenColumns : [ [ {
                title : 'id',
                field : 'id',
                width : 40,
                hidden : true
            } ] ],
            columns : [ [ {
                field : 'type',
                title : '类型',
                width : 50
            },{
                field : 'index',
                title : '类型编号',
                width : 50
            },{
                field : 'name',
                title : '名称 ',
                width : 80
            },{
                field : 'desc',
                title : '产品介绍',
                width : 130
            },{
                field: 'status',
                title: '状态',
                width: '80',
                sortable:true,
                formatter : function(value, row, index){
                    switch (value){
                        case 0:
                            return '启用';
                        case 1:
                            return '禁用 ';
                    }
                }
            },{
                width : '150',
                title : '创建时间',
                field : 'createTime'
            },{
                field : 'updateId',
                title : '处理人',
                width : 50
            }, {
                width : '150',
                title : '处理时间',
                field : 'updateTime'
            }, {
                    width : '250',
                    title : '图片',
                    field : 'titleImg',
                    sortable : true,
                    formatter : function(value) {
                        var str = '';
                        str += '<img src="'+value+'"  />';
                        return str;
                    }
                },{
                field : 'action',
                title : '操作',
                width : 180,
                formatter : function(value, row, index) {
                    var str = '';
                        <%--<shiro:hasPermission name="/wechatService/edit">   data-options="plain:true,iconCls:\'fi-x icon-red\'
                            str += '&nbsp;&nbsp;&nbsp;&nbsp;';
                            str += $.formatString('<a href="javascript:void(0)" class="wechatService-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editAppCarouselFigureFun(\'{0}\');" >编辑</a>', row.id);
                        </shiro:hasPermission>--%>
                    str += $.formatString('<a href="javascript:void(0)" class="wechatService-easyui-linkbutton-edit" data-options="plain:true,iconCls:\'fi-pencil icon-blue\'" onclick="editWechatService(\'{0}\');" >编辑</a>', row.id);
                    str += '&nbsp;&nbsp;|&nbsp;&nbsp;';
                    str += $.formatString('<a href="javascript:void(0)" class="wechatService-easyui-linkbutton-del" data-options="plain:true,iconCls:\'fi-x icon-red\'" onclick="wechatServiceDel(\'{0}\',\'{1}\');" >删除</a>', row.id);
                    return str;
                }
            } ] ],
            onLoadSuccess:function(data){
                $('.wechatService-easyui-linkbutton-edit').linkbutton({text:'编辑'});
                $('.wechatService-easyui-linkbutton-del').linkbutton({text:'删除'});
            },
            toolbar : '#appVipToolBar'
        });
    });


    /**
     * 新增微信客服
     * */
    function addWechatService(){
        parent.$.modalDialog({
            title : '添加微信客服',
            width : 700,
            height : 500,
            href : '${path }/wechatService/addPage',
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = wechatServiceDataGrid;//因为添加成功之后，需要刷新这个treeGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#wechatServiceAddForm');
                    f.submit();
                }
            }, {
                text : '取消',
                handler : function() {
                    console.info( parent.$.modalDialog);
                    parent.$.modalDialog.handler.dialog('close');
                }
            }
            ]
        });
    }

    function editWechatService(id) {
        if (id == undefined) {
            var rows = wechatServiceDataGrid.datagrid('getSelections');
            id = rows[0].id;
        } else {
            wechatServiceDataGrid.datagrid('unselectAll').datagrid('uncheckAll');
        }
        parent.$.modalDialog({
            title : '编辑',
            width : 500,
            height : 300,
            href : '${path }/wechatService/editPage?id=' + id,
            buttons : [ {
                text : '确定',
                handler : function() {
                    parent.$.modalDialog.openner_dataGrid = wechatServiceDataGrid;//因为添加成功之后，需要刷新这个dataGrid，所以先预定义好
                    var f = parent.$.modalDialog.handler.find('#wechatServiceEditForm');
                    f.submit();
                }
            } ]
        });
    }

    function wechatServiceDel(id) {
        parent.$.messager.confirm('询问', '您是否要删除？', function(b) {
            if (b) {
                $.post('${path }/wechatService/delete', {
                    id : id
                }, function(result) {
                    if (result.success) {
                        parent.$.messager.alert('提示', result.msg, 'info');
                        wechatServiceDataGrid.datagrid('reload');
                    }else{
                        parent.$.messager.alert('提示', result.msg, 'info');
                        wechatServiceDataGrid.datagrid('reload');
                    }
                }, 'JSON');
            }
        });
    }

</script>
<div class="easyui-layout" data-options="fit:true,border:false">
    <div data-options="region:'center',fit:true,border:false">
        <table id="wechatServiceDataGrid" data-options="fit:true,border:false"></table>
    </div>
</div>
<div id="appVipToolBar" style="display: none;">
    <a onclick="addWechatService();" href="javascript:void(0);" class="easyui-linkbutton" data-options="plain:true,iconCls:'fi-plus icon-green'">添加</a>
</div>

